package com.wdf.rule.drools;

import org.drools.compiler.kie.builder.impl.InternalKieModule;
import org.drools.compiler.kie.builder.impl.KieBuilderImpl;
import org.drools.compiler.kie.builder.impl.KieModuleKieProject;
import org.kie.api.builder.KieBuilder;
import org.kie.api.builder.KieFileSystem;

/**
 * @author wangdingfu
 * @date 2023-11-16 22:35:04
 */
public class FuRuleKieBuilderImpl extends KieBuilderImpl {
    private final ClassLoader classLoader;

    public FuRuleKieBuilderImpl(KieFileSystem kieFileSystem, ClassLoader classLoader) {
        super(kieFileSystem);
        this.classLoader = classLoader;
    }


    @Override
    public KieBuilder buildAll(Class<? extends ProjectType> projectClass) {
        if (projectClass.equals(FuRuleProjectType.class)) {
            return super.buildAll((InternalKieModule kieModule, ClassLoader parent) -> new KieModuleKieProject(kieModule, classLoader), o -> true);
        }
        return super.buildAll(projectClass);
    }
}
